<template>
    <Modal v-model="Is_show" width="500" :styles="{top: '20vh'}" @on-cancel="onClose">
        <p slot="header"></p>
        <div class="bargaining_title">
            <h1>3秒估算家具定制报价</h1>
            <h4>
                <span>每天限</span>
                <span>100</span>
                <span>个名额</span>
            </h4>
        </div>
        <Form ref="formInline" :model="formInline" :rules="ruleInline" inline :show-message="true">
			<FormItem prop="name" label="姓名">
				<div class="item">
					<Input type="text" v-model="formInline.name" placeholder="请输入您的姓名"></Input>
				</div>
			</FormItem>
			<FormItem prop="tel" label="手机号">
				<div class="item">
					<Input maxlength="11" type="text" v-model="formInline.tel" placeholder="请输入手机号码"></Input>
				</div>
			</FormItem>
			<FormItem prop="area" label="面积">
				<div class="item area">
					<Input type="text" suffix=" " v-model="formInline.area" placeholder="请输入房屋面积"></Input>
				</div>
			</FormItem>
            <FormItem>
                <Button :loading="loading" type="error" @click="handleSubmit('formInline')">立即申请</Button>
            </FormItem>
    	</Form>
        <div slot="footer"></div>
    </Modal>
</template>
<script>
import {mapState,mapMutations} from 'vuex'
export default {
    props: {
      is_show:{
          type:Boolean,
          default:false
      },
    },
    data(){
        const validateTel = (rule, value, callback) => {
            if(!(/^1[3456789]\d{9}$/.test(this.formInline.tel))){ 
                callback(new Error('电话格式不正确'));
            } else{
                callback();   
            }
        }
        const validateArea = (rule, value, callback) => {
            if(isNaN(this.formInline.area)){ 
                callback(new Error('面积格式不正确'));
            } else{
                callback();   
            }
        }
        return{
            formInline: {
                name: '',//预约姓名
                tel: '',//预约电话
				area:'',//预约面积
            },
            Is_show:null,
            loading:false,
            ruleInline: {
                name: [
                    { required: true, message: '请输入您的姓名', trigger: 'blur' }
                ],
                tel: [
                    { required: true, message: '请输入您的电话', trigger: 'blur' },
					{ type: 'string', min: 7,message: '电话格式不正确', trigger: 'change' },
                    { required: true,validator:validateTel, trigger: 'change' }
                ],
				area: [
                    { required: true, message: '请输入面积', trigger: 'blur' },
                    { required: true,validator:validateArea, trigger: 'change' }
                ]
            }
        }
    },
    created(){
        
    },
    computed:{
		...mapState(['address'])
	},
    methods:{
        // 立即申请
		handleSubmit(name) {
            this.$refs[name].validate((valid) => {
                if (valid) {
                    this._setUserAppointment(this.formInline)
                } else {
                    // this.$Message.error('Fail!');
                }
            })
        },
        async _setUserAppointment(e){
            this.loading = true
			let {data:{code,data,msg}} = await this.$http.post(this.$API.index.setUserAppointment,{
				name:e.name,
				mobile:e.tel,
				desc:e.area,
                type:3
			})
            this.loading = false
            if(code==200){
                // this.$Message.success(msg);
                this.$emit('onClose',false)
                this.$emit('onSuccess',{
                    title:'已提成功提交申请',
                    des:msg,
                })
            }else{
                this.$Message.error(msg);
            }
		},
        // 关闭
        onClose(){
            console.log('Is_show----------------',this.Is_show)
            this.formInline= {
                name: '',//预约姓名
                tel: '',//预约电话
				area:'',//预约面积
            }
            this.$emit('onClose',false)
        }
    },
    watch:{
        is_show(val, oldVal){//普通的watch监听
            console.log('value----------------',val)
            this.Is_show = val
        }
    }
}
</script>
<style scoped>
    >>>.ivu-modal-content{
        background: #FFFFFF url(~/static/image/popupbg.png)left top no-repeat;
    }
    >>>.ivu-modal-body{
        padding: 40px 80px 56px 80px;
    }
    .bargaining_title{
        text-align: center;
        margin-bottom: 53px;
    }
    .bargaining_title h1{
        font-size: 30px;
        font-weight: 400;
        color: #333333;
        line-height: 40px;
    }
    .bargaining_title h4 span{
        font-size: 16px;
        font-weight: 400;
        color: #333333;
        line-height: 40px;
    }
    .bargaining_title h4 span:nth-child(2){
        color: #F30213;
    }
    >>>.ivu-form-item-content{
        width: 278px;
        height: 40px;
    }
    >>>.ivu-modal-header{
        border-bottom: 0;
        padding: 0;
    }
    >>>.ivu-modal-footer{
        border-top: 0;
        padding: 0;
    }
    >>>.ivu-form-inline .ivu-form-item{
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 0;
        margin-bottom: 30px;
    }
    .area>>>.ivu-icon::after{
		content: '㎡';
		color: #333333;
		line-height: 40px;

	}
    >>>.ivu-form-item-content .item,.item>>>input{
        height: 40px;
    }
    >>>.ivu-form .ivu-form-item-label{
        text-align: left;
        width: 80px;
    }
    >>>.ivu-form-item-content{
        width: 340px;
        height: 40px;
       
    }

    button{
        width: 100%;
        height: 100%;
        background: #F30213;
        border-radius: 6px;
        font-size: 16px;
        font-weight: 400;
        color: #FFFFFF;
    }
</style>
